package com.itheima.test7;

import javax.swing.text.DateFormatter;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.util.Timer;
import java.util.TimerTask;

public class Test {
    public static void main(String[] args) {
        //定时任务对象
        Timer timer = new Timer();
        //定时任务方法
        while (true) {
            LocalTime now = LocalTime.now();
            LocalTime target = LocalTime.of(6, 30, 00);
            long seconds = Duration.between(now, target).getSeconds();
            if (seconds == 0) {
                timer.scheduleAtFixedRate(new TimerTask() {
                    int count = 0;
                    @Override
                    public void run() {
                        count++;
                        method(count);
                    }
                }, 1000, 1000 * 60 * 5);
                break;
            }
        }
        //delay 延迟加载  1000：代表延迟一秒执行
        //period 周期，1000：每一秒执行一次
    }

    public static void method(int count) {
        System.out.println("我是一个小闹钟！！");
        if (count == 10) {
            System.exit(0);
        }
    }
}
